package com.shop.controller;

import com.shop.base.BaseController;
import com.shop.result.ResultVO;
import com.shop.service.FileService;
import com.shop.util.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author XCH
 * @date 2025-06
 * 暂时无法调用
 */
@RestController
@RequestMapping("/files")
public class MultiFileUploadController extends BaseController {

    private final FileService fileService;

    public MultiFileUploadController(FileService fileService) {
        this.fileService = fileService;
    }

    /*
     * 上传文件到服务器返回文件访问路径
     * @param file 文件
     * */
    @PostMapping("/upload")
    public ResultVO<String> uploadFile(@RequestParam("image") MultipartFile file) {

        System.out.println("上传文件: " + file.getOriginalFilename());
        String result = fileService.uploadFile(file);
        System.out.println(result);
        return success(result);
    }

    /**
     * 批量上传文件到服务器返回文件访问路径数组
     * @param files 文件数组
     * @return 文件访问路径数组，JSON格式
     */
    @PostMapping("/uploadMultiple")
    public ResultVO<String> uploadFiles(@RequestParam("images") MultipartFile[] files) {
        String result = fileService.uploadFiles(files);
        System.out.println("批量上传结果: " + result);
        return success(result);
    }

}